package b_and_b_properties;

/**
 *
 * @author Omea
 */
public class CheckBoxConverter {

    public static final int CLEARALL = 0;
    public static final int BOX1 = 1;
    public static final int BOX2 = 2;
    public static final int BOX3 = 4;
    public static final int BOX4 = 8;
    public static final int BOX5 = 16;
    public static final int BOX6 = 32;
    public static final int BOX7 = 64;
    public static final int BOX8 = 128;
    public static final int BOX9 = 256;
    public static final int BOX10 = 512;
    public static final int BOX11 = 1024;
    public static final int BOX12 = 2048;
    public static final int BOX13 = 4096;
    public static final int BOX14 = 8192;
    public static final int BOX15 = 16384;
    public static final int BOX16 = 32768;
    public static final int BOX17 = 65536;
    public static final int BOX18 = 131072;
    public static final int BOX19 = 262144;
    public static final int BOX20 = 524288;
    public static final int BOX21 = 1048576;
    public static final int BOX22 = 2097152;
    public static final int BOX23 = 4194304;
    public static final int BOX24 = 8388608;
    public static final int BOX25 = 16777216;
    public static final int BOX26 = 33554432;
    public static final int BOX27 = 67108864;
    public static final int BOX28 = 134217728;
    public static final int BOX29 = 268435456;
    public static final int BOX30 = 536870912;
    private int data = 0;
    private int numBoxes;
    private int max;

    public CheckBoxConverter(int number_of_boxes) {
        //cbe = new CBEnum(number_of_boxes);
//        if (number_of_boxes > 1) {
        this.numBoxes = number_of_boxes;
        this.max = number_of_boxes + 1;
//        }
    }

    /**
     * @return the max
     */
    public int getMax() {
        return max;
    }

    /**
     * @return the current value
     */
    public int getValue() {
        return data;
    }

    public void set(int idx) {
        data |= idx;
//        if (idx > 0) {
//            if (idx < max) {
//            }
//        }
    }

    public void clearAll() {
        data = 0;
    }

    public void clear(int idx) {
        data &= ~idx;
//        if ((idx > 0) && (idx <= numBoxes)) {
//        }
    }

//    public boolean checkOff(int idx) {
//        int check = 0;
//        if (idx > BOX1) {
//            return false;
//        }
//        if (idx < 1) {
//            return false;
//        }
//        return ((idx & data) == check);
//    }

    public boolean checkOn(int idx) {
        if (idx > numBoxes) {
            return false;
        }
        if (idx < 1) {
            return false;
        }
        return ((idx & data) == idx);
    }
}
    
